//
//  IMFCMPushModels.h
//  DualMediationSDK
//
//  Created by YeJary on 2025/1/27.
//

#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>

@class UIViewController;

NS_ASSUME_NONNULL_BEGIN

/**
 * FCM推送配置模型
 */
@interface IMFCMPushConfig : NSObject

/// 目标视图控制器类（点击通知时打开）
@property (nonatomic, strong, nullable) Class targetViewControllerClass;

/// 自定义数据处理回调
@property (nonatomic, copy, nullable) void(^customDataHandler)(NSDictionary *userInfo);

/// 是否在前台显示通知
@property (nonatomic, assign) BOOL showNotificationInForeground;

/// 是否自动处理通知点击
@property (nonatomic, assign) BOOL autoHandleNotificationTap;

/// 通知声音文件名
@property (nonatomic, copy, nullable) NSString *soundFileName;

/**
 * 创建默认配置
 * @return 配置实例
 */
+ (instancetype)defaultConfig;

/**
 * 创建带目标视图控制器的配置
 * @param targetClass 目标视图控制器类
 * @return 配置实例
 */
+ (instancetype)configWithTargetViewControllerClass:(Class)targetClass;

@end

/**
 * FCM推送结果模型
 */
@interface IMFCMPushResult : NSObject

/// 是否成功
@property (nonatomic, assign, readonly) BOOL success;

/// 错误码（失败时）
@property (nonatomic, assign, readonly) NSInteger errorCode;

/// 错误信息（失败时）
@property (nonatomic, copy, readonly, nullable) NSString *errorMessage;

/// FCM令牌
@property (nonatomic, copy, readonly, nullable) NSString *fcmToken;

/**
 * 创建成功结果
 * @param fcmToken FCM令牌
 * @return 结果实例
 */
+ (instancetype)successWithToken:(nullable NSString *)fcmToken;

/**
 * 创建失败结果
 * @param errorCode 错误码
 * @param errorMessage 错误信息
 * @return 结果实例
 */
+ (instancetype)failureWithCode:(NSInteger)errorCode message:(NSString *)errorMessage;

@end

/**
 * FCM推送通知信息
 */
@interface IMFCMNotificationInfo : NSObject

/// 通知标题
@property (nonatomic, copy, readonly, nullable) NSString *title;

/// 通知内容
@property (nonatomic, copy, readonly, nullable) NSString *body;

/// 自定义数据
@property (nonatomic, strong, readonly, nullable) NSDictionary *customData;

/// 通知来源（前台/后台/点击）
@property (nonatomic, copy, readonly) NSString *source;

/// 接收时间
@property (nonatomic, strong, readonly) NSDate *receivedTime;

/**
 * 从用户信息创建通知信息
 * @param userInfo 推送用户信息
 * @param source 来源描述
 * @return 通知信息实例
 */
+ (instancetype)infoWithUserInfo:(NSDictionary *)userInfo source:(NSString *)source;

@end

/**
 * FCM推送回调
 * @param result 初始化结果
 */
typedef void(^IMFCMPushCompletionBlock)(IMFCMPushResult *result);

/**
 * FCM通知接收回调
 * @param notificationInfo 通知信息
 */
typedef void(^IMFCMNotificationReceivedBlock)(IMFCMNotificationInfo *notificationInfo);

/**
 * FCM令牌更新回调
 * @param token 新的FCM令牌
 */
typedef void(^IMFCMTokenRefreshBlock)(NSString *token);

NS_ASSUME_NONNULL_END